package com.cn.icss.validator;

import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import org.apache.commons.lang3.StringUtils;

/**
 * @中软华腾软件系统有限公司,未经授权不得擅自传播
 * @类描述: 评论验证
 * @类名称:StreamValidator
 * @作者: Administrator
 * @编辑时间: 2020/04/08 19:12
 * @版本: 1.0
 */
public class CommentValidator extends BaseValidator {

    @Override
    protected void validate(Controller c) {
        setRet(Ret.fail());// 官网推荐
        // 判断写各个方法的验证
        switch (super.getActionMethodName()) {

            case "saveComment":{
                super.validateRequired("targetId", "comment_targetId_msg","评论对象不能为空");
                super.validateRequired("userId", "comment_userId_msg","评论用户Id不能为空");
                super.validateRequired("userName", "comment_userName_msg","评论用户名称不能为空");
                super.validateRequired("content", "comment_content_msg","评论内容不为空");
                break;
            }
            case "findCommentSplit": {
                super.validateRequired("targetId", "comment_targetId_msg", "评论对象不能为空");
                if(StringUtils.isNotBlank(c.getPara("pageNum"))){
                    super.validateInteger("pageNum", "comment_page_msg", "分页参数页码必须整数");
//                    super.validateRegex("pageNum", "^$|^[1-9]\\d*$", "comment_page_msg", "分页参数页码必须整数");
                }
                if(StringUtils.isNotBlank(c.getPara("pageSize"))){
//                    super.validateRegex("pageSize", "^$|^[1-9]\\d*$", "comment_limit_msg", "分页参数每页显示数量必须整数");
                    super.validateInteger("pageSize", "comment_limit_msg", "分页参数每页显示数量必须整数");
                }
                break;
            }
            default: {

            }

        }

    }

}
